/*
 * @Author jiangzhiwei
 * @Date 2023-07-20 10:19:27
 * @LastEditors jiangzhiwei
 * @LastEditTime 2023-07-28 11:39:53
 * @FilePath \test-cron\src\components\yc-cron\components\base\common-li\index.js
 * @Description 选项列表
 */
import { isVue2, defineComponent } from 'vue-demi'
import { h } from '../../../utils/domutil'
import { getSlot } from '../../../utils/componentutil'
import { VALUE_NAME } from '../../../utils/constant'
import CommonRadio from '../common-radio'
import './li.css'

const NAME = 'yc-cron-li'

export default defineComponent({
  name: NAME,
  components: { CommonRadio },
  props: {
    [VALUE_NAME]: {
      type: [String, Number, Boolean],
      default: undefined
    },
    /** radio的label */
    label: {
      type: [String, Number, Boolean],
      default: undefined
    }
  },
  methods: {
    onInput () {
      if (isVue2) {
        this.$emit('input', this.label)
      } else {
        this.$emit('update:modelValue', this.label)
      }
    },
    onClick () {
      this.$emit('update:modelValue', this.label)
    }
  },
  render () {
    return h(
      'li',
      {
        class: { [NAME]: true, 'is-active': this[VALUE_NAME] === this.label },
        on: { click: this.onClick }
      },
      [
        h(
          CommonRadio,
          {
            props: { label: this.label, [VALUE_NAME]: this[VALUE_NAME] },
            on: { input: this.onInput }
          },
          getSlot(this)
        ),
        getSlot(this, 'content')
      ]
    )
  }
})